package com.bh.web.controller.shipment;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.shipment.domain.JcShipmentTrack;
import com.bh.shipment.service.IJcShipmentTrackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 运单追踪Controller
 *
 * @author slx
 * @date 2024-03-08
 */
@RestController
@RequestMapping("/shipment/track")
public class JcShipmentTrackController extends BaseController
{
    @Autowired
    private IJcShipmentTrackService jcShipmentTrackService;

    /**
     * 查询运单追踪列表
     */
    @ApiOperation("查询运单追踪列表")
    @PreAuthorize("@ss.hasPermi('shipment:track:list')")
    @GetMapping("/trackList/{jcShipmentId}")
    public AjaxResult trackList(@PathVariable("jcShipmentId") Long jcShipmentId)
    {
        JcShipmentTrack jcShipmentTrack = new JcShipmentTrack();
        jcShipmentTrack.setJcShipmentId(jcShipmentId);
        List<JcShipmentTrack> list = jcShipmentTrackService.selectJcShipmentTrackList(jcShipmentTrack);
        return AjaxResult.success(list);
    }


    /**
     * 获取运单轨迹
     */
    @ApiOperation("获取运单轨迹")
    @GetMapping("/trackForString/{shipmentId}")
    public AjaxResult getTrackForString(@PathVariable Long shipmentId) {
        return AjaxResult.success("成功！", jcShipmentTrackService.getTrackForString(shipmentId));
    }

    /**
     * 导出运单追踪列表
     */
    @PreAuthorize("@ss.hasPermi('shipment:track:export')")
    @Log(title = "运单追踪", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcShipmentTrack jcShipmentTrack)
    {
        List<JcShipmentTrack> list = jcShipmentTrackService.selectJcShipmentTrackList(jcShipmentTrack);
        ExcelUtil<JcShipmentTrack> util = new ExcelUtil<>(JcShipmentTrack.class);
        util.exportExcel(response, list, "运单追踪数据");
    }

    /**
     * 获取运单追踪详细信息
     */
    @ApiOperation("获取运单追踪详细信息")
    @PreAuthorize("@ss.hasPermi('shipment:track:query')")
    @GetMapping( "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jcShipmentTrackService.selectJcShipmentTrackById(id));
    }

    /**
     * 新增运单追踪
     */
    @ApiOperation("新增运单追踪")
    @PreAuthorize("@ss.hasPermi('shipment:track:add')")
    @Log(title = "运单追踪", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcShipmentTrack jcShipmentTrack)
    {
        return toAjax(jcShipmentTrackService.insertJcShipmentTrack(jcShipmentTrack));
    }
}